package com.acmen.easyapi.executor;

import com.acmen.easyapi.enums.BasicCode;
import com.acmen.easyapi.model.Response;
import com.acmen.easyapi.repository.UnitTestRepository;
import com.acmen.easyapi.util.RequestUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author acmen
 * 删除测试执行器
 */
@Component
public class UnitTestDelExe {
    @Value("${cmp.api.intranetIp:*}")
    private String intranetIp;
    @Resource
    private UnitTestRepository unitTestRepository;
    /**
     * 删除单元测试
     *
     * @param id
     * @return
     */
    public Response delete(String id) {
        String ip = RequestUtil.getIpAddress();
        if(!(ip.matches(intranetIp.replace("*",".*"))||ip.startsWith("127.0."))){
            return Response.failure(BasicCode.FORBIDDEN.getCode(),"不允许操作！");
        }
        return Response.build(unitTestRepository.delete(id));
    }
}
